﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace _1stVATCWin
{
    public partial class BH_ADD : Form
    {
        public BH_ADD()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "";
            if (name.Text == "" || tel.Text == "" || seri.Text == "")
                label2.Text = "Xin nhập đầy đủ dữ liệu";
            else
            {
                label2.Text = "Đã thêm dữ liệu thành công";
                this.DialogResult = DialogResult.OK;

                Config file = new Config(Application.StartupPath + "\\config.ini");
                string connectionString = file.ReadValue("server", "conn");
                //string connectionString = @"Data Source=FOX-PC\SQLEXPRESS;Initial Catalog=Project;Integrated Security=True";
                SqlConnection conn = new SqlConnection(connectionString);
                string sql = "insert into BAOHANH(tenkhachhang,sodt,ngaybaohanh,serinumber,tinhtrang) values(@name,@dt,@ngay,@seri,@tt)";
                SqlCommand cmd = new SqlCommand(sql, conn);;               

                cmd.Parameters.AddWithValue("@name", name.Text);
                cmd.Parameters.AddWithValue("@dt", tel.Text);
                cmd.Parameters.AddWithValue("@ngay", DateTime.Today);
                cmd.Parameters.AddWithValue("@seri", seri.Text);
                cmd.Parameters.AddWithValue("@tt", description.Text);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();                    
            }
        }
    }
}
